package RuntimeInfo;

import ShapeModel.*;
import AppView.*;
import java.awt.*;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.LinkedList;


/**
 * 记录各种状态的类
 */
public class State{

    public static CanvasSection canvas;
    public static CADShape current = null; // 当前选中的图形
    public static int curType = 0; // 当前选中图形的类型
    public static Color curColor = Color.BLACK;
    public static float curStroke = 1.0f;
    public static Point2D originFocusPoint = null;// 被选取的形状的起始时的左上角点、
    public static int cursorState = State.CREATE;
    public static Point pressPoint = null;// 记录拖动，创建图形时上一帧按下的点的位置
    public static boolean canCreate = false;// 是否创建新图形
    public static LinkedList<CADShape> shapeList = new LinkedList<>();// 当前画布中的所有图形
    public static String text;

    public static File curFile = null; // 当前打开的文件


    public static final int NONTYPE = 0;
    public static final int LINE = 1;
    public static final int RECTANGLE = 2;
    public static final int ELLIPSE = 3;
    public static final int TEXT = 4;

    public static final int FREE = 0;
    public static final int TOP = 1;
    public static final int BOTTOM = 2;
    public static final int LEFT = 3;
    public static final int RIGHT = 4;
    public static final int DRAG = 5;
    public static final int CREATE = 6;


    /**
     * 聚焦函数和失焦函数提供对状态的操作，可以减少一致性问题带来的bug
     * 赋值current，originFocusPoint，curColor和curStroke
     *
     * @param shape 要聚焦的对象
     */
    public static void focusOn(CADShape shape) {
        current = shape;
        if (shape instanceof CADLine) curType = State.LINE;
        else if (shape instanceof CADEllipse) curType = State.ELLIPSE;
        else if (shape instanceof CADRectangle) curType = State.RECTANGLE;
        else if (shape instanceof CADText) curType = State.TEXT;
        else curType = State.NONTYPE;

        curColor = shape.getColor();
        curStroke = shape.getStrokeWidth();
        originFocusPoint = shape.getPoint();
    }

    /**
     * 让当前状态失去焦点
     */
    public static void loseFocus() {
        current = null;
        curType = State.NONTYPE;
        originFocusPoint = null;
        pressPoint = null;
        cursorState = State.FREE;
        canCreate = false;
    }

    /**
     * 将当前的状态情况，在关闭当前文件时使用
     */
    public static void clear(){
        loseFocus();
        curFile = null;
        shapeList.clear();
    }

    /**
     * 打印State的信息
     */
    public static void printInfo(){
        System.out.println("File:"+curFile.getPath());
        System.out.println("Shape count : "+shapeList.size());
    }

}

